package com.ruoyi.web;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.MyTokenService;
import com.ruoyi.system.domain.Seeker;
import com.ruoyi.system.domain.SeekerPdfRelation;
import com.ruoyi.system.domain.Upfile;
import com.ruoyi.system.service.IBlogDetailsService;
import com.ruoyi.system.service.ISeekerPdfRelationService;
import com.ruoyi.system.service.ISeekerService;
import com.ruoyi.system.service.IUpfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class ResumeViewController {
    @Autowired
    private ISeekerService seekerService;
    @Autowired
    private ISeekerPdfRelationService seekerPdfRelationService;
    @Autowired
    private IUpfileService upfileService;
    @Autowired
    private MyTokenService myTokenService;
    @RequestMapping("/resumedetail")
    public AjaxResult resumedetail(@RequestParam("id")String id,@RequestParam("token")String token){
        if(id!=null&&id!="") {
            Map<String, Object> re = new HashMap<>();
            re.put("seeker", seekerService.selectSeekerBySeekerId(Long.valueOf(id)));
            SeekerPdfRelation seekerPdfRelation = seekerPdfRelationService.selectSeekerPdfRelationBySeekerId(Long.valueOf(id));
            Upfile upfile = null;
            if (seekerPdfRelation != null) {
                upfile = upfileService.selectUpfileByFileId(seekerPdfRelation.getPdfId());
            }
            re.put("upfile", upfile);
            return new AjaxResult(200, "返回信息", re);
        }
        else{
            //seeker身份
            Long tokenid  = myTokenService.getloginid(token);
            Map<String, Object> re = new HashMap<>();

            re.put("seeker", seekerService.selectSeekerBySeekerId(tokenid));
            SeekerPdfRelation seekerPdfRelation = seekerPdfRelationService.selectSeekerPdfRelationBySeekerId(tokenid);
            Upfile upfile = null;
            if (seekerPdfRelation != null) {
                upfile = upfileService.selectUpfileByFileId(seekerPdfRelation.getPdfId());
            }
            re.put("upfile", upfile);
            return new AjaxResult(200, "返回信息", re);
        }
    }
}
